home *** CD-ROM | disk | FTP | other *** search
/ Ian & Stuart's Australian Mac 1993 September / September 93.iso / Archives / Utilities / Security - care / Protect / Tonto / Str.c < prev    next >
Text File  |  1991-11-26  |  1KB  |  86 lines

  1. /* Str routines */
  2. # include    <Dialogs.h>
  3. # include    <Events.h>
  4. # include    <Menus.h>
  5. # include    "tonto.h"
  6.  
  7. void
  8. SetNameStr (name, line)
  9. StringPtr    name;
  10. StringPtr    line;
  11. /* Gets the named string & sets it to line.  If not found, creates it*/
  12. {
  13.     Handle    myHndl;
  14.     Str255    s;
  15.     Size    len;
  16.  
  17.     len = (Size) line[0] + 1;
  18.     myHndl = GetNamedResource ('STR ', (SP) name);    
  19.     if (myHndl == NULL) 
  20.     {
  21.         myHndl = NewHandle (len);
  22.         if (!myHndl)
  23.             return;
  24.         pstrcpy ((SP)(*myHndl), line);
  25.         AddResource (myHndl, 'STR ', UniqueID('STR '), (SP)name);
  26.     }
  27.     else
  28.     {
  29.         HNoPurge (myHndl);
  30.         SetHandleSize (myHndl, len);
  31.         pstrcpy ((SP)(*myHndl), line);
  32.         ChangedResource(myHndl);
  33.         HPurge (myHndl);
  34.     }
  35.     WriteResource (myHndl);
  36. }
  37.  
  38. int
  39. GetNamedStr (name, line)
  40. /* returns 0 if not found, 1 if found */
  41. StringPtr    name;
  42. StringPtr    line;
  43. {
  44.     Handle    myHndl;
  45.  
  46.     myHndl = GetNamedResource ('STR ', (SP)name);
  47.     if (!myHndl) {
  48.         line[0] = 0;
  49.         return(0);
  50.     }
  51.     pstrcpy (line, (SP)(*myHndl));
  52.     return(1);
  53. }
  54.  
  55. StringPtr
  56. pstrcpy (dest, src)
  57. StringPtr    dest;
  58. StringPtr    src;
  59. {
  60.     BlockMove (src, dest, (Size)(src[0]) + 1);
  61.     return dest;
  62. }
  63.  
  64. StringPtr
  65. pstrcat (dest, src)
  66. StringPtr    dest, src;
  67. {
  68.     int    lens, lend;
  69.     
  70.     lens = src[0];
  71.     lend = dest[0];
  72.     if (lens + lend < 255) {
  73.         BlockMove (src + 1, dest + lend+1, (Size)lens);
  74.         dest[0] = lens + lend;
  75.     }
  76.     return dest;
  77. }
  78.  
  79. StringPtr
  80. pstrcat2 (dest, src1, src2)
  81. StringPtr dest, src1, src2;
  82. {
  83.     if (dest != src1)
  84.         pstrcpy (dest, src1);
  85.     return (pstrcat (dest, src2));
  86. }